package com.dx.controller;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.dx.pojo.Account;
import com.dx.pojo.Finding;
import com.dx.pojo.FindingDetail;
import com.dx.pojo.Findingdata;
import com.dx.pojo.ItemCondition;
import com.dx.pojo.ItemsCategory;
import com.dx.pojo.ItemsDetail;
import com.dx.pojo.LocPicking;
import com.dx.pojo.LosingDeal;
import com.dx.pojo.LosingInfo;
import com.dx.pojo.LosingPage;
import com.dx.pojo.Losingdata;
import com.dx.pojo.PicPage;
import com.dx.pojo.PickingDeal;
import com.dx.pojo.PickingInfo;
import com.dx.pojo.UserDetail;
import com.dx.pojo.UserRelative;
import com.dx.pojo.losingItemInfo;
import com.dx.pojo.pickItemInfo;
import com.dx.service.AccountService;
import com.dx.service.ItemsService;
import com.dx.service.LocationService;

@Controller
public class ItemsController {
	@Resource
	private ItemsService itemsService;
	@Resource
	private LocationService locationService;
	@Resource
	private AccountService accountService;

	@RequestMapping("/user/allcategory")
	public @ResponseBody List<ItemsCategory> allcategory() {
		List<ItemsCategory> list = itemsService.showallcate();
		return list;
	}

	@RequestMapping("/user/alllocation")
	public @ResponseBody List<LocPicking> alllocation() {
		List<LocPicking> list = locationService.queryallloc();
		return list;
	}

	@RequestMapping("/user/submititem")
	public void submititem(HttpServletRequest req, HttpServletResponse rep,MultipartFile picture,HttpSession session)
			throws Exception {
		 ItemsDetail itemsDetail=new ItemsDetail();
		 LosingInfo losinfInfo=new LosingInfo();
		 PickingInfo pickingInfo=new PickingInfo();
		 int n=0;
		 Account account=(Account) session.getAttribute("account");
		 UserDetail user=accountService.selectusername(account);
		 System.out.println(user.getPhoneNumber());
		 String UserInfoId=user.getUserInfoId();
		 //获得是否是丢失还是拾取
		 int losorpicid=Integer.parseInt(req.getParameter("selecttype"));
		 //获得物品参数类别
		 String itemid = req.getParameter("selectitem");
		 int id=Integer.parseInt(itemid);
		 itemsDetail.setCategoryId(itemid);
	     itemsDetail.setItemsName(itemsService.itemsCatename(id));
		 //获得卡的编号
	     String cardid=req.getParameter("cardId");
	     //获取简单物品描述
	     String itemdescription=new String(req.getParameter("itemsDescripton").getBytes(),"utf-8");
	     System.out.println(itemdescription);
	     itemsDetail.setItemsDescripton(itemdescription);
	     //获取联系方式
	     String phone=req.getParameter("phone");
	     //获取姓名
	     String name=new String(req.getParameter("name").getBytes(),"utf-8");
	     System.out.println(name);
	     //获取暂存地点
	     String locid=req.getParameter("selecttemploc");
	     //获取电子邮件
	     String email=req.getParameter("email");
	     //获取时间
	     String time=req.getParameter("time");
	     //获取地点
	     String location=req.getParameter("itemlocation");
	     System.out.println(location);
	     //获得详细介绍
	     String detaildesc=new String(req.getParameter("detaildescription").getBytes(),"utf-8");
	     System.out.println(detaildesc);
	     itemsDetail.setDetaildescription(detaildesc);
	     if (picture != null) {
				// 图片上传成功后，将图片地址存入数据库
				String filepath = "C:\\graduationpic";
				String originalpath = picture.getOriginalFilename();

				String newfilename = UUID.randomUUID().toString().replaceAll("-", "")
						+ originalpath.substring(originalpath.lastIndexOf("."));
				// 新文件
				File f = new File(filepath +"\\"+ newfilename);
				// 图片存入内存
				picture.transferTo(f);
				// pojo对象设置名字
				itemsDetail.setPicture(newfilename);
			}
	     //丢失编号存入丢失表
	     if(losorpicid==1){
	    	 if(id>=1&&id<=4){
	    		 //存入卡号
	    		 itemsDetail.setCardId(cardid);
	    	 }else{
	    		 itemsDetail.setCardId(null);
	    	 }
	    	 itemsDetail.setStatusId("1");
	    	 itemsDetail.setCheckdeal("0");
	    	 itemsDetail.setItemlocation(location);
	    	 int i=itemsService.insertItems(itemsDetail);
	    	 if(i==1){
	    		 losinfInfo.setUserDetail(user);
	    		 if(name.equals("匿名")==true){
	    			 losinfInfo.getUserDetail().setUserName("匿名");
	    		 }
	    		 if(phone.equals("")!=true){
	    			 losinfInfo.getUserDetail().setPhoneNumber(phone);
	    		 }
	    		 losinfInfo.setCategoryID(id);
	    		 losinfInfo.setLosingTime(time);	 
	    		 losinfInfo.setItemsDetail(itemsDetail);
	    		 n=itemsService.insertLosing(losinfInfo);
	    	 }
	     }
	     //找回编号存入拾取表
	     else if(losorpicid==2){
	    	 if(id>=1&&id<=4){
	    		 //存入卡号
	    		 itemsDetail.setCardId(cardid);
	    	 }else{
	    		 itemsDetail.setCardId(null);
	    	 }
	    	 itemsDetail.setStatusId("2");
	    	 itemsDetail.setCheckdeal("0");
	    	 itemsDetail.setItemlocation(location);
	    	 
	    	 int i=itemsService.insertItems(itemsDetail);
	    	 if(i==1){
	    		 pickingInfo.setCategoryID(id);
	    		 pickingInfo.setUserDetail(user);
	    		 pickingInfo.setLocid(Integer.parseInt(locid));
	    		 if(name.equals("匿名")==true){
	    			 pickingInfo.getUserDetail().setUserName("匿名");
	    		 }
	    		 if(phone!=null){
	    			 pickingInfo.getUserDetail().setPhoneNumber(phone);
	    		 }
	    		 pickingInfo.setPickerTime(time);
	    		 pickingInfo.setItemsDetail(itemsDetail);
	    		 pickingInfo.setUserInfoId(UserInfoId);
	    		 n=itemsService.insertPicking(pickingInfo);
	    	 }
	     }
	     if(n!=0){
	    	 rep.setContentType("text/html; charset=utf-8");
	    	 PrintWriter pw=rep.getWriter();
	    	 pw.print("<script>alert('添加成功')</script>");
	    	 pw.print("<script>location.href='http://localhost:8080/graduation/user/main.jsp'</script>");
	    	 pw.close();
	     }else{
	    	 rep.setContentType("text/html; charset=utf-8");
	    	 PrintWriter pw=rep.getWriter();
	    	 pw.print("<script>alert('修改失败，返回页面重新填写')</script>");
	    	 pw.print("<script>location.href='http://localhost:8080/graduation/user/DeatilItem.jsp'</script>");
	    	 pw.close();
	     }
	     	    
	}
	
	//失物信息展示
	 @RequestMapping("/user/querylosing")
     public @ResponseBody LosingPage querylosing(HttpServletRequest request,String currentpage,String categoryID){
		 LosingInfo losinginfo=new LosingInfo();
		 if(currentpage==null){
			 losinginfo.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 losinginfo.setPageindex(pageindex*5);
		 }
		 System.out.println(categoryID+"cate");
		 if(categoryID!=null){
			 int id=Integer.parseInt(categoryID);
			 if(id!=0){
				 losinginfo.setCategoryID(id);
			 }
		 }
		 losinginfo.setItemsDetail(new ItemsDetail());
		 losinginfo.setUserDetail(new UserDetail());
    	 List<LosingInfo> list=itemsService.querylosinginfo(losinginfo);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    	 }
    	 //设置失物分页
    	 LosingPage losingpage=new LosingPage();
    	 losingpage.setLosinginfo(list);
    	 int count=itemsService.countalllosing(losinginfo);
    	 losingpage.setCount(count);
    	 if(currentpage==null){
    		 losingpage.setCurrentpage(0);
		 }else{
			 losingpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return losingpage;
     }
	 
	 @RequestMapping("/admin/queryunlosing")
     public @ResponseBody LosingPage queryunlosing(HttpServletRequest request,String currentpage,
    		             String categoryID,String checkdeal,String itemsDescription){
		 LosingInfo losinginfo=new LosingInfo();
		 if(currentpage==null){
			 losinginfo.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 losinginfo.setPageindex(pageindex*5);
		 }
		 System.out.println(categoryID+"cate");
		 if(categoryID!=null){
			 int id=Integer.parseInt(categoryID);
			 if(id!=0){
				 losinginfo.setCategoryID(id);
			 }
		 }
		 if("".equals(itemsDescription)||itemsDescription==null){
			 losinginfo.setItemsDescription(null);
		 }else{
			 losinginfo.setItemsDescription(itemsDescription);
		 }
		 losinginfo.setCheckdeal(checkdeal);
		 losinginfo.setItemsDetail(new ItemsDetail());
		 losinginfo.setUserDetail(new UserDetail());
    	 List<LosingInfo> list=itemsService.selectunlosinginfo(losinginfo);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    	 }
    	 //设置失物分页
    	 LosingPage losingpage=new LosingPage();
    	 losingpage.setLosinginfo(list);
    	 int count=itemsService.selectcountallunlosing(losinginfo);
    	 losingpage.setCount(count);
    	 if(currentpage==null){
    		 losingpage.setCurrentpage(0);
		 }else{
			 losingpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return losingpage;
     }
	 
	 
	 @RequestMapping("/user/queryuserlosing")
     public @ResponseBody LosingPage queryuserlosing(HttpServletRequest request,String currentpage,HttpSession session){
		 Account account=(Account) session.getAttribute("account");
		 UserDetail userdetail=accountService.selectusername(account);
		 LosingInfo losinginfo=new LosingInfo();
		 losinginfo.setUserInfoId(userdetail.getUserInfoId());
		 System.out.println(userdetail.getUserInfoId());
		 if(currentpage==null){
			 losinginfo.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 losinginfo.setPageindex(pageindex*5);
		 }
    	 List<LosingInfo> list=itemsService.selectuserlosing(losinginfo);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    		 System.out.println(list.get(i).toString()+"mmmm");
    	 }
    	 //设置失物分页
    	 LosingPage losingpage=new LosingPage();
    	 losingpage.setLosinginfo(list);
    	 int count=itemsService.selectcountuserlosing(losinginfo);
    	 losingpage.setCount(count);
    	 if(currentpage==null){
    		 losingpage.setCurrentpage(0);
		 }else{
			 losingpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return losingpage;
     }
	 
	 @RequestMapping("/admin/queryunpicking")
     public @ResponseBody PicPage queryunpicking(HttpServletRequest request,String currentpage,
    		             String categoryID,String checkdeal,String itemsDescription){
		 PickingInfo pickinginfo=new PickingInfo();
		 if(currentpage==null){
			 pickinginfo.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 pickinginfo.setPageindex(pageindex*5);
		 }
		 if(categoryID!=null){
			 int id=Integer.parseInt(categoryID);
			 if(id!=0){
				 pickinginfo.setCategoryID(id);
			 }
		 }
		 if("".equals(itemsDescription)||itemsDescription==null){
			 pickinginfo.setItemsDescription(null);
		 }else{
			 pickinginfo.setItemsDescription(itemsDescription);
		 }
		 pickinginfo.setCheckdeal(checkdeal);
		 List<PickingInfo> list=itemsService.selectunpickinginfo(pickinginfo);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    	 }
    	 //设置失物分页
    	 PicPage picpage=new PicPage();
    	 picpage.setPickInfo(list);
    	 int count=itemsService.selectcountallunpicking(pickinginfo);
    	 if(count!=0){
    		 picpage.setCount(count);   
    	 } 
    	 if(currentpage==null){
    		 picpage.setCurrentpage(0);
		 }else{
			 picpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return picpage;
     }
	 
    //寻物信息展示
	 @RequestMapping("/user/querypicking")
	 public @ResponseBody PicPage querypicking(HttpServletRequest request,String currentpage,String categoryID){
		 PickingInfo pickinginfo=new PickingInfo();
		 if(currentpage==null){
			 pickinginfo.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 pickinginfo.setPageindex(pageindex*5);
		 }
		 if(categoryID!=null){
			 int id=Integer.parseInt(categoryID);
			 if(id!=0){
				 pickinginfo.setCategoryID(id);
			 }
		 }
    	 List<PickingInfo> list=itemsService.querypickinginfo(pickinginfo);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    	 }
    	 //设置失物分页
    	 PicPage picpage=new PicPage();
    	 picpage.setPickInfo(list);
    	 int count=itemsService.countallpicking(pickinginfo);
    	 if(count!=0){
    		 picpage.setCount(count);   
    	 } 
    	 if(currentpage==null){
    		 picpage.setCurrentpage(0);
		 }else{
			 picpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return picpage;
     }
	 

	 
	 @RequestMapping("/user/queryuserpicking")
	 public @ResponseBody PicPage queryuserpicking(HttpServletRequest request,String currentpage,HttpSession session){
		 PickingInfo pickinginfo=new PickingInfo();
		 Account account=(Account) session.getAttribute("account");
		 UserDetail userdetail=accountService.selectusername(account);
		 System.out.println(userdetail.getUserInfoId());
		 pickinginfo.setUserInfoId(userdetail.getUserInfoId());
		 if(currentpage==null){
			 pickinginfo.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 pickinginfo.setPageindex(pageindex*5);
		 }
    	 List<PickingInfo> list=itemsService.selectuserpicking(pickinginfo);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    	 }
    	 //设置失物分页
    	 PicPage picpage=new PicPage();
    	 picpage.setPickInfo(list);
    	 int count=itemsService.selectcountuserpicking(pickinginfo);
    	 picpage.setCount(count);  
    	 if(currentpage==null){
    		 picpage.setCurrentpage(0);
		 }else{
			 picpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return picpage;
     }
	 
	 
	 @RequestMapping("/user/pickdetail")
	 public @ResponseBody pickItemInfo pickdetail(String picid){
		   pickItemInfo pickitem=itemsService.selectdetailpicking(picid);
		   int id=pickitem.getLocid();
		   pickitem.setLocationaddress(locationService.quertlocname(id));
		   return pickitem;
	 }
	 
	 @RequestMapping("/user/losdetail")
	 public @ResponseBody losingItemInfo losdetail(String picid){
		 losingItemInfo lositem=itemsService.selectdetaillosing(picid);
		 return lositem;
	 }
	 
	 @RequestMapping("/admin/updatelosedeal")
	 public @ResponseBody String updatelosedeal(LosingDeal losingdeal){
		 int n=itemsService.updatelosingcheckdeal(losingdeal);
	     if(n!=0){
	    	 return "1";
	     }else{
	    	 return "0";
	     }	 
	 }
	 
	 @RequestMapping("/admin/updatepickdeal")
	 public @ResponseBody String updatepickdeal(PickingDeal pickingDeal){
		 int n=itemsService.updatepickingcheckdeal(pickingDeal);
	     if(n!=0){
	    	 return "1";
	     }else{
	    	 return "0";
	     }	 
	 }
	 
	 @RequestMapping("/admin/losingdata")
	 @ResponseBody
	 public List<Losingdata> querylosingdata(){
		 List<Losingdata> losingdata=itemsService.losingdatashow();
		 return losingdata;
	 }
	 
	 @RequestMapping("/admin/pickingdata")
	 @ResponseBody
	 public List<Losingdata> querypickingdata(){
		 List<Losingdata> losingdata=itemsService.pickingdatashow();
		 return losingdata;
	 }
	 
	 @RequestMapping("/user/relative")
	 @ResponseBody
	 public List relative(HttpSession session){
		 List list=new ArrayList<>();
		 Account account=(Account) session.getAttribute("account");
		 UserDetail userDetail=accountService.selectusername(account);
		 List<UserRelative> listuser=itemsService.userrelative(userDetail.getUserInfoId());
		 System.out.println(listuser.size());
		 int i=0;
		 for(int j=0;j<listuser.size();j++){
			 UserRelative userRelative=listuser.get(j);
			 List<PickingInfo> listpick=itemsService.userrelpic(userRelative);
			 System.out.println(listpick);
			 int index=0;
			 if(listpick.size()!=0){
				 list.add( listpick);
				 int count=itemsService.countuserrelpic(userRelative);
				 i+=count;
				 list.add(count);
			 }
//			 list.add(listpick);
			 
					
		 }
		 
		 return list;
	 }
	 
	 @RequestMapping("/admin/confirmitem")
	 @ResponseBody
	 public int confirmitem(String id){
		 return itemsService.confirmitem(id);
	 }
	 
	 //模糊查询
	 @RequestMapping("/admin/confirmbycondition")
	 @ResponseBody
	 public PicPage confirmbycondition(ItemCondition itemCondition,String currentpage){
		 if(currentpage==null){
			 itemCondition.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 itemCondition.setPageindex(pageindex*5);
		 }
    	 List<PickingInfo> list=itemsService.confirmbycondition(itemCondition);
    	 for(int i=0;i<list.size();i++){
    		 list.get(i).setCategoryName(itemsService.itemsCatename(list.get(i).getCategoryID()));
    	 }
    	 //设置失物分页
    	 PicPage picpage=new PicPage();
    	 picpage.setPickInfo(list);
    	 int count=itemsService.countconfirmbycondition(itemCondition);
    	 picpage.setCount(count);  
    	 if(currentpage==null){
    		 picpage.setCurrentpage(0);
		 }else{
			 picpage.setCurrentpage(Integer.parseInt(currentpage));
		 }
    	 return picpage;
		 
	 }
	 
	 //添加招领记录
	 @RequestMapping("/admin/insertfinding")
	 @ResponseBody
	 public int insertfinding(Finding finding){		 
		 int n=itemsService.insertfinding(finding);
		 return n;
	 }
	 
	 @RequestMapping("/admin/queryfinding")
	 @ResponseBody
	 public List<FindingDetail> queryfindingdetail(FindingDetail findingDetail,String currentpage,String findRecordsId){
		 System.out.println("你好"+findRecordsId);
		 if(currentpage==null){
			 findingDetail.setPageindex(0);
		 }else{
			 int pageindex=Integer.parseInt(currentpage);
			 findingDetail.setPageindex(pageindex*5);
		 }
		 int n=itemsService.countquerybyfinding(findingDetail);
		 if(findRecordsId!=null){
			 findingDetail.setFindRecordsId(findRecordsId);
		 }
		 List<FindingDetail> list=itemsService.querybyfinding(findingDetail);
		 for(int i=0;i<list.size();i++){
			 list.get(i).setCount(n);
			 if(currentpage==null){
				 findingDetail.setPageindex(0);
			 }else{
				 int pageindex=Integer.parseInt(currentpage);
				 list.get(i).setPageindex(pageindex*5);
			 }
			
		 }
		 return list;
	 }
	 
	 @RequestMapping("/admin/findingdata")
	 @ResponseBody
	 public List<Findingdata> queryfindingdata(){
		 List<Findingdata> Findingdata=itemsService.queryallfinding();
		 return Findingdata;
	 }
	 
	 @RequestMapping("/user/cancelloseitem")
	 @ResponseBody
	 public String cancelloseitem(String id){
		 int n=itemsService.cancelloseitem(id);
		 if(n!=0){
			 return "success";
		 }else{
			 return "error";
		 }
	 }
	 
	 @RequestMapping("/user/updatelos")
	 public void updatelos(HttpServletRequest req, HttpServletResponse rep,MultipartFile picture,HttpSession session)
				throws Exception {
			 ItemsDetail itemsDetail=new ItemsDetail();
			 LosingInfo losinfInfo=new LosingInfo();	 
			 int n=0;
			 Account account=(Account) session.getAttribute("account");
			 UserDetail user=accountService.selectusername(account);
			 System.out.println(user.getPhoneNumber());
			 String UserInfoId=user.getUserInfoId();
			
			 //获得物品参数类别
			 String itemid = req.getParameter("selectitem");
			 int id=Integer.parseInt(itemid);
			 itemsDetail.setCategoryId(itemid);
		     itemsDetail.setItemsName(itemsService.itemsCatename(id));
			 //获得卡的编号
		     String cardid=req.getParameter("cardId");
		     //获取简单物品描述
		     String itemdescription=new String(req.getParameter("itemsDescripton").getBytes(),"utf-8");
		     System.out.println(itemdescription);
		     itemsDetail.setItemsDescripton(itemdescription);
		     //获取联系方式
		     String phone=req.getParameter("phone");
		     itemsDetail.setPhone(phone);
		     //获取姓名
		     String name=new String(req.getParameter("name").getBytes(),"utf-8");
		     System.out.println(name);
		     //获取暂存地点
		     String locid=req.getParameter("selecttemploc");
		     //获取电子邮件
		     String email=req.getParameter("email");
		     //获取时间
		     String time=req.getParameter("time");
		     itemsDetail.setLosingTime(time);
		     //获取地点
		     String location=req.getParameter("itemlocation");
		     itemsDetail.setItemlocation(location);
		     String losid=req.getParameter("losingId");
		    // System.out.println(location);
		     //获得详细介绍
		     String detaildesc=new String(req.getParameter("detaildescription").getBytes(),"utf-8");
		     System.out.println(detaildesc);
		     itemsDetail.setDetaildescription(detaildesc);
		     if (picture != null) {
					// 图片上传成功后，将图片地址存入数据库
					String filepath = "C:\\graduationpic";
					String originalpath = picture.getOriginalFilename();

					String newfilename = UUID.randomUUID().toString().replaceAll("-", "")
							+ originalpath.substring(originalpath.lastIndexOf("."));
					// 新文件
					File f = new File(filepath +"\\"+ newfilename);
					// 图片存入内存
					picture.transferTo(f);
					// pojo对象设置名字
					itemsDetail.setPicture(newfilename);
				}
		     //丢失编号存入丢失表
		    	 if(id>=1&&id<=4){
		    		 //存入卡号
		    		 itemsDetail.setCardId(cardid);
		    	 }else{
		    		 itemsDetail.setCardId(null);
		    	 }
		    	 itemsDetail.setStatusId("1");
		    	 itemsDetail.setCheckdeal("0");
		    	 itemsDetail.setLosingId(losid);
		    	 int i=itemsService.updatelos(itemsDetail);
		    	 
		     
		     //找回编号存入拾取表	     
		     if(i!=0){
		    	 rep.setContentType("text/html; charset=utf-8");
		    	 PrintWriter pw=rep.getWriter();
		    	 pw.print("<script>alert('修改成功')</script>");
		    	 pw.print("<script>location.href='http://localhost:8080/graduation/user/Personal.jsp'</script>");
		    	 pw.close();
		     }else{
		    	 rep.setContentType("text/html; charset=utf-8");
		    	 PrintWriter pw=rep.getWriter();
		    	 pw.print("<script>alert('修改失败，返回页面重新填写')</script>");
		    	 pw.print("<script>location.href='http://localhost:8080/graduation/user/Personal.jsp'</script>");
		    	 pw.close();
		     }
		     	    
		}
	 
	 @RequestMapping("/admin/deletelose")
	 @ResponseBody
	 public int deletelose(String id){
		 int n=itemsService.deletelose(id);
		 if(n!=0){
			 return 1;
		 }else{
			 return 0;
		 }
	 }
	 
	 @RequestMapping("/admin/deletepic")
	 @ResponseBody
	 public int deletepic(String id){
		 int n=itemsService.deletepic(id);
		 if(n!=0){
			 return 1;
		 }else{
			 return 0;
		 }
	 }
	 
	 @RequestMapping("/admin/updatepic")
	 @ResponseBody
	 public int updatepic(ItemsDetail itemsDetail,HttpServletRequest req){
		 String desc=req.getParameter("itemsDescripton");
		 System.out.println(desc);
		 String losid=req.getParameter("losingId");
		 itemsDetail.setLosingId(losid);
		 String losingTime=req.getParameter("losingTime");
		 System.out.println(losingTime);
		 String phone=req.getParameter("phone");
		 System.out.println(phone);
		 itemsDetail.setDetaildescription(desc);
		 itemsDetail.setLosingTime(losingTime);
		 itemsDetail.setPhone(phone);
		 int n=itemsService.updatepic(itemsDetail);
		 if(n!=0){
			 return 1;
		 }else{
			 return 0;
		 }
	 }
	 
}
